package onelinechart;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

//管理具体的曲线型--AILineChart--的Manager，里面有个ID-AILineChart键值对map，有利于添加多条AI曲线
public class AIChartManager {
	// 针对一个图里面可能有多条曲线而设计
	private Map<String, AILineChart> lineChartMap;

	public AIChartManager() {
		lineChartMap = new HashMap<String, AILineChart>();
	}

	public boolean isMonitor(String devid) {
			return lineChartMap.containsKey(devid);
	}

	public AILineChart getAILineChart(String devid){
		return lineChartMap.get(devid);
	}

	public AILineChart createAILineChart(RealAIInfo realAIInfo) {
		return createAILineChart(realAIInfo, null);
	}

	public AILineChart createAILineChart(RealAIInfo realAIInfo,
			String color) {
		AILineChart aiLineChart = new AILineChart();
		aiLineChart.setRealAIInfo(realAIInfo, color);
		lineChartMap.put(realAIInfo.getDevId(), aiLineChart);
		return aiLineChart;
	}

	public static AIChartManager getSessionAIChartManager(HttpSession session) {
		final String attrName = "CHART_MANAGER";
		AIChartManager result = null;
		Object o = session.getAttribute(attrName);
		if (o != null) {
			result = (AIChartManager) o;
		} else {
			result = new AIChartManager();
			session.setAttribute(attrName, result);
		}
		return result;
	}
}